package com.wwwarehouse.carddesk.fragment.teamfragment.checkdownclassfragemnt;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.github.lzyzsd.jsbridge.BridgeHandler;
import com.github.lzyzsd.jsbridge.BridgeWebView;
import com.github.lzyzsd.jsbridge.CallBackFunction;
import com.wwwarehouse.carddesk.R;
import com.wwwarehouse.carddesk.bean.CardDeskGroupGetGroupBean;
import com.wwwarehouse.carddesk.bean.GroupHtmlDataBean;
import com.wwwarehouse.carddesk.bean.teambean.AllPowerDetailBean;
import com.wwwarehouse.carddesk.bean.teambean.BusinessUnitsBean;
import com.wwwarehouse.carddesk.constant.CardDeskConstant;
import com.wwwarehouse.carddesk.custom_view.NewLineFlexLayout;
import com.wwwarehouse.carddesk.eventbus_event.CardDeskGroupEvent;
import com.wwwarehouse.carddesk.fragment.teamfragment.checkupclassfragment.AllPowerFragment;
import com.wwwarehouse.carddesk.fragment.teamfragment.commenttargetweb.AgeingTargetFragmnent;
import com.wwwarehouse.carddesk.fragment.teamfragment.commenttargetweb.EfficiencyTargetFragmnent;
import com.wwwarehouse.carddesk.fragment.teamfragment.commenttargetweb.QualityTargetFragmnent;
import com.wwwarehouse.common.activity.BaseCardDeskActivity;
import com.wwwarehouse.common.activity.base.BaseApplication;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.common.constant.Constant;
import com.wwwarehouse.common.custom_widget.CircleImageView;
import com.wwwarehouse.common.custom_widget.ElasticScrollView;
import com.wwwarehouse.common.custom_widget.button.StateButton;
import com.wwwarehouse.common.custom_widget.state_layout.StateLayout;
import com.wwwarehouse.common.custom_widget.time_pick.ChoosePickerDialog;
import com.wwwarehouse.common.http.NoHttpUtils;
import com.wwwarehouse.common.tools.ConvertUtils;
import com.wwwarehouse.common.tools.LogUtils;
import com.wwwarehouse.common.tools.PopUpUtils;
import com.wwwarehouse.common.tools.ToastUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import de.greenrobot.event.EventBus;

/**
 * @创建者 chenchao.
 * @创建时间 2017/11/9 19:47
 * @描述 ${TODO}
 * 上啦延迟 上啦下属 下拉分配权限 下拉回收权限
 */

public class CheckDownClassFragment extends BaseFragment implements View.OnClickListener {

    private View                               mView;
    private ElasticScrollView                  mElasticScrollView;
    private boolean                            isShow;
    private StateLayout                        mStateLayout;
    private RelativeLayout                     mRlElse;
    private RelativeLayout.LayoutParams        mParams;
    private CircleImageView                    mCivLeadHead;
    private TextView                           mTvLeadName;
    private CircleImageView                    mCivHead;
    private TextView                           mTvName;
    private TextView                           mTvMore;
    private NewLineFlexLayout                  mLineFlexLayout;
    private LinearLayout                       mLlDetail;
    private TextView                           mTvTeamName;
    private BridgeWebView                      mBwWebView;
    private StateButton                        mBtConnect;
    private StateButton                        mBtBackTeam;
    private StateButton                        mBtDelay;
    private StateButton                        mBtUnder;
    private ImageView                          mIvAsk;
    private CardDeskGroupGetGroupBean.ListBean mBean;
    private CardDeskGroupGetGroupBean.ListBean mBean2;
    private CardDeskGroupGetGroupBean.ListBean mBean1;
    private Bundle                             mToDelayBundle;
    private DelayTaskFragment                  mDelayTaskFragment;
    private Bundle                             mToDownClassBundle;
    private DownClassFragment                  mDownClassFragment;
    private String                             mUserId;
    private Map<String, Object>                mMapUnit;
    private ArrayList<String>                  mUnitNameList;
    private String                             powerType;
    private List<BusinessUnitsBean>            mBusinessUnitsList;
    private LinearLayout                       mLlHaveData;
    private LinearLayout                       mLlNoData;
    private String mNewUrl;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_check_down_class, container, false);
        initView();
        return mView;
    }

    private void initView() {

        mElasticScrollView = findView(mView, R.id.esv_elastic);
        mStateLayout = findView(mView, R.id.sl_layout);
        mRlElse = findView(mView, R.id.rl_else);
        mParams = (RelativeLayout.LayoutParams) mRlElse.getLayoutParams();
        mCivLeadHead = findView(mView, R.id.civ_lead_head);
        mTvLeadName = findView(mView, R.id.tv_laed_name);
        mCivHead = findView(mView, R.id.civ_head);
        mTvName = findView(mView, R.id.tv_name);
        mTvMore = findView(mView, R.id.tv_more);
        mLineFlexLayout = findView(mView, R.id.new_line_layout);
        mLlDetail = findView(mView, R.id.ll_detail);
        mIvAsk = findView(mView, R.id.iv_ask);
        mTvTeamName = findView(mView, R.id.tv_team_name);
        mBwWebView = findView(mView, R.id.bw_web_view);
        mLlHaveData = findView(mView, R.id.ll_have_data);
        mLlNoData = findView(mView, R.id.ll_no_data);
        mBtConnect = findView(mView, R.id.bt_connect);
        mBtBackTeam = findView(mView, R.id.bt_back_team);
        mBtDelay = findView(mView, R.id.bt_delay);
        mBtUnder = findView(mView, R.id.bt_under);

        mTvMore.setOnClickListener(this);
        mLlDetail.setOnClickListener(this);
        mBtConnect.setOnClickListener(this);
        mBtBackTeam.setOnClickListener(this);
        mBtDelay.setOnClickListener(this);
        mBtUnder.setOnClickListener(this);
        ((BaseCardDeskActivity) mActivity).setTitleBt2Text(mActivity.getResources().getString(R.string.teamdesk_recover_power));
        ((BaseCardDeskActivity) mActivity).setTitleBt1Text(mActivity.getResources().getString(R.string.teamdesk_distribute_power));

        mElasticScrollView.setOnPullListener(new ElasticScrollView.OnPullListener() {
            @Override
            public void onDownPull() {
                //只有从团队桌面进来才可能有 分配权限 回收权限
                if (mBean1 != null) {
                    //只要是晓飞那边直接进来到下级的 这两个按钮肯定要出现
                    ((BaseCardDeskActivity) mActivity).showTitleBt2();
                    ((BaseCardDeskActivity) mActivity).downPull_3();
                } /*else if (mBean2 != null) {
                    mMapUnit.put("userId", mUserId);//授权人
                    mMapUnit.put("beAuthorizedId", mBean2.getUserId());//被授权人
                }*/
            }

            @Override
            public void onUpPull() {
                if (!isShow) {
                    if (mBean1 != null && 1 == mBean1.getIsDelayed()) {
                        mBtDelay.setVisibility(View.VISIBLE);
                    } else if (mBean2 != null && 1==mBean2.getIsDelayed()) {
                        mBtDelay.setVisibility(View.VISIBLE);
                    }
                    mBtUnder.setVisibility(View.VISIBLE);
                    mParams.setMargins(ConvertUtils.dip2px(mActivity, 11), ConvertUtils.dip2px(mActivity, 5), ConvertUtils.dip2px(mActivity, 11), ConvertUtils.dip2px(mActivity, 59));
                    mRlElse.setLayoutParams(mParams);
                } else {
                    mBtDelay.setVisibility(View.INVISIBLE);
                    mBtUnder.setVisibility(View.INVISIBLE);
                    mParams.setMargins(ConvertUtils.dip2px(mActivity, 11), ConvertUtils.dip2px(mActivity, 5), ConvertUtils.dip2px(mActivity, 11), ConvertUtils.dip2px(mActivity, 36));
                    mRlElse.setLayoutParams(mParams);
                }
                isShow = !isShow;
            }
        });
        String env = sp.getValue(Constant.sp_Env, sp.getValue(Constant.sp_EnvDefault, Constant.ENV_DEFAULT));
        if (Constant.ENV_DEV.equals(env)) {
            mBaseUrl = Constant.URL_WEB_BASE_DEV;
        } else if (Constant.ENV_CIT.equals(env)) {
            mBaseUrl = Constant.URL_WEB_BASE_CIT;
        } else if (Constant.ENV_SIT.equals(env)) {
            mBaseUrl = "";
        } else if (Constant.ENV_UAT.equals(env)) {
            mBaseUrl = Constant.URL_WEB_BASE_UAT;
        } else if (Constant.ENV_RELEASE.equals(env)) {
            mBaseUrl = Constant.URL_WEB_BASE_RELEASE;
        } else if (Constant.ENV_CIT2.equals(env)) {
            mBaseUrl = Constant.URL_WEB_BASE_CIT2;
        }
        mNewUrl = mBaseUrl + CardDeskConstant.PATH_GROUP_PARTR_H5_URL;
        //        bundleBean = getArguments().getParcelable("bean");
        mBwWebView.loadUrl(mNewUrl);
        mStateLayout.showProgressView(true);
        mBwWebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                if (newProgress == 100) {
                    mStateLayout.showContentView();
                } else {
                }
            }
        });


    }

    private String mBaseUrl = "";
//    private CardDeskGroupGetGroupBean.ListBean bundleBean;
    private String                             data;

    private void registJsMethod() {

        final GroupHtmlDataBean bean = new GroupHtmlDataBean();
        bean.setToken(BaseApplication.sp.getValue(Constant.sp_Token));

        bean.setRankingCompany(new String[]{});
        bean.setRankingUser(new String[]{});
        bean.setIsTriMember(0);
        if (mBean1 != null) {
            bean.setPrivilegeUp(new String[]{sp.getValue(Constant.sp_User_Id)});
            bean.setPrivilegeDown(new String[]{mBean1.getUserId()});
        } else if (mBean2 != null) {
            bean.setPrivilegeUp(new String[]{mUserId});
            bean.setPrivilegeDown(new String[]{mBean2.getUserId()});
        }


        //        bean.setRankingCompany(new String[]{"10"});
        //        bean.setRankingUser(new String[]{"1"});
        //        bean.setIsTriMember(1);
        //        bean.setPrivilegeUp("");
        //        bean.setPrivilegeDown("");

        data = JSON.toJSON(bean).toString();

        //Js获取请求的参数
        mBwWebView.callHandler("getData", data, new CallBackFunction() {
            @Override
            public void onCallBack(String responseData) {
                ToastUtils.showToast(responseData);
            }
        });

        //隐藏StateLayout和ProgressDialog
        mBwWebView.registerHandler("hideProgress", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                //                dismissProgressDialog();
                mStateLayout.showContentView();
            }
        });

        //显示progressDialog
        mBwWebView.registerHandler("showProgress", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                //                showProgressDialog("正在加载...");
                mStateLayout.showProgressView(true);
            }
        });

        //显示错误信息
        mBwWebView.registerHandler("showErrorMsg", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                //                dismissProgressDialog();
                //                toast("" + data);
                mStateLayout.showSystemView(true);
                mStateLayout.setSystemListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mBwWebView.loadUrl(mNewUrl);
                        //        mBwWebView.loadUrl("http://192.168.72.177:8888/app/teamFrame/teamMember.html");
                        mStateLayout.showProgressView(true);
                    }
                });
            }
        });

        //显示没有数据view
        mBwWebView.registerHandler("showNotData", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                mLlHaveData.setVisibility(View.GONE);
                //                dismissProgressDialog();
                mStateLayout.showContentView();
                mLlNoData.setVisibility(View.VISIBLE);
            }
        });

        //点击时效
        mBwWebView.registerHandler("gotoAging", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                Bundle bundle = new Bundle();
                bundle.putInt("IsTriMember", 0);
                if (mBean1 != null) {
                    bundle.putStringArray("up", new String[]{sp.getValue(Constant.sp_User_Id)});
                    bundle.putStringArray("down", new String[]{mBean1.getUserId()});
                    bundle.putParcelable("bean", mBean1);
                } else if (mBean2 != null) {
                    bundle.putStringArray("up", new String[]{mUserId});
                    bundle.putStringArray("down", new String[]{mBean2.getUserId()});
                    bundle.putParcelable("bean", mBean2);
                }

                AgeingTargetFragmnent fragment = new AgeingTargetFragmnent();
                fragment.setArguments(bundle);
                pushFragment(fragment);
            }
        });

        //点击效率
        mBwWebView.registerHandler("gotoEffective", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                Bundle bundle = new Bundle();
                bundle.putInt("IsTriMember", 0);
                if (mBean1 != null) {
                    bundle.putStringArray("up", new String[]{sp.getValue(Constant.sp_User_Id)});
                    bundle.putStringArray("down", new String[]{mBean1.getUserId()});
                    bundle.putParcelable("bean", mBean1);
                } else if (mBean2 != null) {
                    bundle.putStringArray("up", new String[]{mUserId});
                    bundle.putStringArray("down", new String[]{mBean2.getUserId()});
                    bundle.putParcelable("bean", mBean1);
                }
                EfficiencyTargetFragmnent fragmnent = new EfficiencyTargetFragmnent();
                fragmnent.setArguments(bundle);
                pushFragment(fragmnent);
            }
        });

        //点击品质
        mBwWebView.registerHandler("gotoQuality", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                Bundle bundle = new Bundle();
                bundle.putInt("IsTriMember", 0);
                if (mBean1 != null) {
                    bundle.putStringArray("up", new String[]{sp.getValue(Constant.sp_User_Id)});
                    bundle.putStringArray("down", new String[]{mBean1.getUserId()});
                    bundle.putParcelable("bean", mBean1);
                } else if (mBean2 != null) {
                    bundle.putStringArray("up", new String[]{mUserId});
                    bundle.putStringArray("down", new String[]{mBean2.getUserId()});
                    bundle.putParcelable("bean", mBean1);
                }
                QualityTargetFragmnent fragmnent = new QualityTargetFragmnent();
                fragmnent.setArguments(bundle);
                pushFragment(fragmnent);
            }
        });

    }

    @Override
    public void titleBt1Click() {
        super.titleBt1Click();
        //分配权限
        powerType = "DISTRIBUTE";
        if (mUnitNameList.size() < 1) {
            mMapUnit.put("userId", sp.getValue(Constant.sp_User_Id));//授权人
            mMapUnit.put("beAuthorizedId", mBean1.getUserId());//被授权人
            //        showProgressDialog();
            NoHttpUtils.httpPost(CardDeskConstant.GET_BUSINESS_UNITS_BY_AUTHOR, mMapUnit, mOnResponseListener, 1);
        } else {
            showEndPop(mActivity.getResources().getString(R.string.teamdesk_select_business_unit), mUnitNameList);
        }

    }

    @Override
    public void titleBt2Click() {
        super.titleBt2Click();
        //回收权限
        powerType = "CALLBACK";
        if (mUnitNameList.size() < 1) {
            mMapUnit.put("userId", sp.getValue(Constant.sp_User_Id));//授权人
            mMapUnit.put("beAuthorizedId", mBean1.getUserId());//被授权人
            //        showProgressDialog();
            NoHttpUtils.httpPost(CardDeskConstant.GET_BUSINESS_UNITS_BY_AUTHOR, mMapUnit, mOnResponseListener, 1);
        } else {
            showEndPop(mActivity.getResources().getString(R.string.teamdesk_select_business_unit), mUnitNameList);
        }

    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof CheckDownClassFragment) {
            mActivity.setTitle(R.string.teamdesk_member);
        }
    }

    private boolean isFristGetBuName = true;
    @Override
    public void requestDatas() {
        //获取业务单位的map
        mMapUnit = new HashMap<>();
        //业务单位名称的集合
        mUnitNameList = new ArrayList();

        //延时详情的bundle以及fragment
        mToDelayBundle = new Bundle();
        mDelayTaskFragment = new DelayTaskFragment();

        //下属的bundle以及fragment
        mToDownClassBundle = new Bundle();
        mDownClassFragment = new DownClassFragment();

        if (getArguments() != null) {
            mBean = getArguments().getParcelable("bean");
            //不是从桌面直接点进来 这时候上级就不是登入的时候保存的
            if (getArguments().getString("leadFaceUrl") != null && getArguments().getString("leadName") != null) {
                String leadFaceUrl = getArguments().getString("leadFaceUrl");
                String leadName = getArguments().getString("leadName");
                mUserId = getArguments().getString("userId");
                BaseApplication.getApplicationInstance().displayImg(leadFaceUrl, mCivLeadHead);
                mTvLeadName.setText(leadName);
                mBean2 = (CardDeskGroupGetGroupBean.ListBean) mBean;
                BaseApplication.getApplicationInstance().displayImg(mBean2.getFaceUrl(), mCivHead);
                mTvName.setText(mBean2.getPersonName());
                mTvTeamName.setText(String.format(mActivity.getResources().getString(R.string.teamdesk_team), mBean2.getPersonName()));
            } else {
                BaseApplication.getApplicationInstance().displayImg(sp.getValue(Constant.sp_Face_Url), mCivLeadHead);
                mTvLeadName.setText(sp.getValue(Constant.sp_Person_Name));
                mBean1 = (CardDeskGroupGetGroupBean.ListBean) mBean;
                BaseApplication.getApplicationInstance().displayImg(mBean1.getFaceUrl(), mCivHead);
                mTvName.setText(mBean1.getPersonName());
                mTvTeamName.setText(String.format(mActivity.getResources().getString(R.string.teamdesk_team), mBean1.getPersonName()));


                //一进来就去请求业务单位 如果失败 再去请求
                mMapUnit.put("userId", sp.getValue(Constant.sp_User_Id));//授权人
                mMapUnit.put("beAuthorizedId", mBean1.getUserId());//被授权人
                //        showProgressDialog();
                NoHttpUtils.httpPost(CardDeskConstant.GET_BUSINESS_UNITS_BY_AUTHOR, mMapUnit, mOnResponseListener, 1);

            }

        }
        //bean 为null了 在initview里请求
        registJsMethod();
        //六个小条 请求权限
        Map<String, Object> powerMap = new HashMap<>();
        powerMap.put("authorityCode", 3);
        if (mBean1 != null) {
            powerMap.put("authorizeTeamUserId", sp.getValue(Constant.sp_User_Id));
            powerMap.put("beauthorizedTeamUserId", mBean1.getUserId());
        } else if (mBean2 != null) {
            powerMap.put("authorizeTeamUserId", mUserId);
            powerMap.put("beauthorizedTeamUserId", mBean2.getUserId());
        }
        powerMap.put("page", 1);
        powerMap.put("size", 7);
        NoHttpUtils.httpPost(CardDeskConstant.GET_RELATIONAUITEM_INFO, powerMap, mOnResponseListener, 0);
    }

    private NoHttpUtils.OnResponseListener mOnResponseListener = new NoHttpUtils.OnResponseListener() {
        @Override
        public void onSucceed(CommonClass commonClass, int what) {
            try {
                switch (what) {
                    case 0:
                        if ("0".equals(commonClass.getCode())) {
                            AllPowerDetailBean allPowerDetailBean = JSON.parseObject(commonClass.getData().toString(), AllPowerDetailBean.class);
                            List<AllPowerDetailBean.ListBean> list = allPowerDetailBean.getList();

                            LayoutInflater inflater = LayoutInflater.from(mActivity);
                            mLineFlexLayout.setMaxLine(3);
                            if (list.size() > 6) {
                                mTvMore.setVisibility(View.VISIBLE);
                                for (int i = 0; i < 6; i++) {
                                    String itemName = list.get(i).getItemName();
                                    TextView tv = (TextView) inflater.inflate(R.layout.team_view_new_line_flex_layout, mLineFlexLayout, false);
                                    tv.setText(itemName);
                                    mLineFlexLayout.addView(tv);
                                }
                            } else {
                                for (int i = 0; i < list.size(); i++) {
                                    String itemName = list.get(i).getItemName();
                                    TextView tv = (TextView) inflater.inflate(R.layout.team_view_new_line_flex_layout, mLineFlexLayout, false);
                                    tv.setText(itemName);
                                    mLineFlexLayout.addView(tv);
                                }
                            }
                        }
                        break;
                    case 1:
                        if ("0".equals(commonClass.getCode())) {
                            mBusinessUnitsList = JSON.parseArray(commonClass.getData().toString(), BusinessUnitsBean.class);
                            if (mBusinessUnitsList.size() > 0) {
                                mUnitNameList.clear();
                                for (int i = 0; i < mBusinessUnitsList.size(); i++) {
                                    mUnitNameList.add(mBusinessUnitsList.get(i).getBuName());
                                }
                                //不是刚进来 第一次请求  而是点击按钮后发现第一次进来请求失败  再次请求
                                if (!isFristGetBuName) {
                                    showEndPop(mActivity.getResources().getString(R.string.teamdesk_select_business_unit), mUnitNameList);
                                }
                                //置为false 为了下次请求可以提示错误信息
                                isFristGetBuName = false;
                            }

                        }
                        break;
                    default:
                        break;
                }
            } catch (Exception e) {
                LogUtils.showLog(e.toString());
            }
        }

        @Override
        public void onFailed(String result, int what) {
            switch (what) {
                case 1:
                    if (!isFristGetBuName) {
                        toast(result);
                    }
                    isFristGetBuName = false;
                    break;
            }

        }
        @Override
        public void onFinish(int what) {
            dismissProgressDialog();
        }
    };

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tv_more) {
            Bundle bundle = new Bundle();
            if (mBean1 != null) {
                bundle.putString("authorizeTeamUserId", sp.getValue(Constant.sp_User_Id));
                bundle.putString("beauthorizedTeamUserId", mBean1.getUserId());
            } else if (mBean2 != null) {
                bundle.putString("authorizeTeamUserId", mUserId);
                bundle.putString("beauthorizedTeamUserId", mBean2.getUserId());
            }
            AllPowerFragment allPowerFragment = new AllPowerFragment();
            allPowerFragment.setArguments(bundle);
            pushFragment(allPowerFragment);
        } else if (id == R.id.ll_detail) {
            if (mBean1 != null) {
                PopUpUtils.showBubbleUpTeam(mIvAsk, mActivity, String.format(mActivity.getResources().getString(R.string.teamdesk_power_from), mBean1.getPersonName(), mBean1.getPersonName()), ConvertUtils.dip2px(mActivity, 11), 0);
            } else if (mBean2 != null) {
                PopUpUtils.showBubbleUpTeam(mIvAsk, mActivity, String.format(mActivity.getResources().getString(R.string.teamdesk_power_from), mBean2.getPersonName(), mBean2.getPersonName()), ConvertUtils.dip2px(mActivity, 11), 0);
            }
        } else if (id == R.id.bt_connect) {
            if (mBean1 != null && !TextUtils.isEmpty(mBean1.getMobile())) {
                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + mBean1.getMobile()));
                startActivity(intent);
            } else if (mBean2 != null && !TextUtils.isEmpty(mBean2.getMobile())) {
                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + mBean2.getMobile()));
                startActivity(intent);
            }
        } else if (id == R.id.bt_back_team) {
            CardDeskGroupEvent cardDeskGroupEvent = new CardDeskGroupEvent("refresh");
            EventBus.getDefault().post(cardDeskGroupEvent);
        } else if (id == R.id.bt_under) {
            if (mBean1 != null) {
                mToDownClassBundle.putString("userId", mBean1.getUserId());
                mToDownClassBundle.putString("leadFaceUrl", mBean1.getFaceUrl());
                mToDownClassBundle.putString("leadName", mBean1.getPersonName());
                mDownClassFragment.setArguments(mToDownClassBundle);
                pushFragment(mDownClassFragment);
            } else if (mBean2 != null) {
                mToDownClassBundle.putString("userId", mBean2.getUserId());
                mToDownClassBundle.putString("leadFaceUrl", mBean2.getFaceUrl());
                mToDownClassBundle.putString("leadName", mBean2.getPersonName());
                mDownClassFragment.setArguments(mToDownClassBundle);
                pushFragment(mDownClassFragment);
            }

        } else if (id == R.id.bt_delay) {
            if (mBean1 != null) {
                mToDelayBundle.putString("userId", mBean1.getUserId());
                mDelayTaskFragment.setArguments(mToDelayBundle);
                pushFragment(mDelayTaskFragment);
            } else if (mBean2 != null) {
                mToDelayBundle.putString("userId", mBean2.getUserId());
                mDelayTaskFragment.setArguments(mToDelayBundle);
                pushFragment(mDelayTaskFragment);
            }

        }
    }

    private void showEndPop(final String s, final ArrayList<String> list) {
        new ChoosePickerDialog.Builder(mActivity).setData(list).setTitle(s).setOnDataSelectedListener(new ChoosePickerDialog.OnSelectedListener() {
            @Override
            public void onSelected(String itemValue, int position) {
                String buId = mBusinessUnitsList.get(position).getBuId();
                if ("DISTRIBUTE".equals(powerType)) {//权限分配
                    Bundle bundle = new Bundle();
                    if (mBean1 != null) {
                        bundle.putString("personName", mBean1.getPersonName());
                        bundle.putString("userId", mBean1.getUserId());
                        bundle.putString("buId", buId);

                    } else if (mBean2 != null) {
                        bundle.putString("personName", mBean2.getPersonName());
                        bundle.putString("userId", mBean2.getUserId());
                        bundle.putString("buId", buId);
                    }
                    bundle.putString("CheckDownClassFragment", "CheckDownClassFragment");
                    pushFragment("/UserCenter/AuthorityDistributePagerFragment", bundle);

                } else if ("CALLBACK".equals(powerType)) {//权限回收
                    Bundle bundle = new Bundle();
                    if (mBean1 != null) {
                        bundle.putString("personName", mBean1.getPersonName());
                        bundle.putString("userId", mBean1.getUserId());
                        bundle.putString("buId", buId);

                    } else if (mBean2 != null) {
                        bundle.putString("personName", mBean2.getPersonName());
                        bundle.putString("userId", mBean2.getUserId());
                        bundle.putString("buId", buId);
                    }
                    TeamPRFragment teamPRFragment = new TeamPRFragment();
                    teamPRFragment.setArguments(bundle);
                    pushFragment(teamPRFragment);
                }
            }

            @Override
            public void onCancel() {

            }
        }).create().show();
    }
}
